package cn.stylefeng.guns.modular.system.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.BasicDeliver;
import cn.stylefeng.guns.modular.system.mapper.BasicDeliverMapper;
import cn.stylefeng.guns.modular.system.model.params.BasicDeliverParam;
import cn.stylefeng.guns.modular.system.model.result.BasicDeliverResult;
import cn.stylefeng.guns.modular.system.service.BasicDeliverService;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * <p>
 * 交付管理表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2019-06-25
 */
@Service
public class BasicDeliverServiceImpl extends ServiceImpl<BasicDeliverMapper, BasicDeliver> implements BasicDeliverService {

    @Override
    public void add(BasicDeliverParam param){
        BasicDeliver entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicDeliverParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicDeliverParam param){
        BasicDeliver oldEntity = getOldEntity(param);
        BasicDeliver newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicDeliverResult findBySpec(BasicDeliverParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<BasicDeliverResult> findListBySpec(BasicDeliverParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicDeliverParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicDeliverParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicDeliver getOldEntity(BasicDeliverParam param) {
        return this.getById(getKey(param));
    }

    private BasicDeliver getEntity(BasicDeliverParam param) {
        BasicDeliver entity = new BasicDeliver();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public BasicDeliverParam getBycustomername(String customername) {
		return this.baseMapper.getBycustomername(customername);
	}

}
